package com.softwareinlife.gae.sample.datastore.model;

import java.util.Date;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.repackaged.com.google.common.collect.Lists;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class UserModel {

	@PrimaryKey
	private String id;

	@Persistent
	private String firstName;

	@Persistent
	private String lastName;

	@Persistent
	private Date createdDate;

	@Persistent(mappedBy = "user", defaultFetchGroup = "true")
	@Element(dependent = "true")
	private List<DeviceModel> phoneNumbers = Lists.newArrayList();

	/**
	 * Constructor
	 */
	public UserModel() {
		super();
	}

	/**
	 * Constructor
	 * 
	 * @param id2
	 * @param string
	 * @param string2
	 */
	public UserModel(String firstName, String lastName) {
		super();
		this.id = firstName;
		this.firstName = firstName;
		this.lastName = lastName;
		this.createdDate = new Date();
	}

	/**
	 * Constructor
	 * 
	 * @param key
	 * @param firstName
	 * @param lastName
	 * @param createdDate
	 * @param phoneNumbers
	 */
	public UserModel(String firstName, String lastName, Date createdDate,
			List<DeviceModel> phoneNumbers) {
		super();
		this.firstName = firstName;
		this.lastName = lastName;
		this.createdDate = createdDate;
		this.phoneNumbers = phoneNumbers;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

	/**
	 * @return the firstName
	 */
	public String getFirstName() {
		return firstName;
	}

	/**
	 * @param firstName
	 *            the firstName to set
	 */
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/**
	 * @return the lastName
	 */
	public String getLastName() {
		return lastName;
	}

	/**
	 * @param lastName
	 *            the lastName to set
	 */
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/**
	 * @return the createdDate
	 */
	public Date getCreatedDate() {
		return createdDate;
	}

	/**
	 * @param createdDate
	 *            the createdDate to set
	 */
	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	/**
	 * @return the phoneNumbers
	 */
	public List<DeviceModel> getPhoneNumbers() {
		return phoneNumbers;
	}

	/**
	 * @param phoneNumbers
	 *            the phoneNumbers to set
	 */
	public void setPhoneNumbers(List<DeviceModel> phoneNumbers) {
		this.phoneNumbers = phoneNumbers;
	}

	/**
	 * @param e
	 * @return
	 * @see java.util.List#add(java.lang.Object)
	 */
	public boolean add(DeviceModel e) {
		return phoneNumbers.add(e);
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "UserModel [id=" + id + ", firstName=" + firstName
				+ ", lastName=" + lastName + ", createdDate=" + createdDate
				+ ", phoneNumbers=" + phoneNumbers + "]";
	}

}
